//
//  JJUploadFilesTask.swift
//  JJAlbumFramework
//
//  Created by 吴梓杭 on 2025/10/17.
//

import Foundation
import Alamofire

struct JJUploadFilesModel {
    var jjAsset: JJAssetModel
    var frontendMd5: String
    var fileData: Data
    var fileName: String
}

enum JJUploadFilesTask {
    // 上传文件
    case uploadFiles(_ model: JJUploadFilesModel)
}

extension JJUploadFilesTask: YMTargetType {
    
    var path: String {
        return "/media/upload"
    }
    
    var parameters: YMParameters {
        switch self {
        case .uploadFiles(let model):
            var params = [String : Any]()
            params["userId"] = JJAlbumConfig.userId
            params["deviceId"] = JJAlbumConfig.deviceId
            params["frontendMd5"] = model.frontendMd5
            return params
        }
    }
    
    var fileData: Data? {
        switch self {
        case .uploadFiles(let model):
            return model.fileData
        }
    }
    
    var fileName: String {
        switch self {
        case .uploadFiles(let model):
            return model.fileName
        }
    }
    
    var requestType: YMRequestType {
        return .uploadFile
    }
    
    var method: YMMethod {
        return .post
    }
    
    var encoding: YMParameterEncoding {
        return URLEncoding.default
    }
    
}
